/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.sql.*;
import java.util.*;
import utils.Tabelas;
import utils.Transaction;

/**
 *
 * @author Felipe
 */
public class FilterData {

    public static LinkedList<FilterDO> buscar(int pesquisa_id, Transaction tr) throws SQLException {
        LinkedList<FilterDO> lista = new LinkedList<FilterDO>();
        Connection c = tr.getConnection();
        String sql = "SELECT * FROM " + Tabelas.FILTRO + " where " + Tabelas.FILTRO_pesquisa_id + " = ? ORDER BY " + Tabelas.FILTRO_user_campo + ", " + Tabelas.FILTRO_operacao + ", " + Tabelas.FILTRO_valor + ";";
        PreparedStatement ps = c.prepareStatement(sql);
        ps.setInt(1, pesquisa_id);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            FilterDO f = new FilterDO();
            f.setPesquisa_id(rs.getInt(Tabelas.FILTRO_pesquisa_id));
            f.setUser_campo(rs.getString(Tabelas.FILTRO_user_campo));
            f.setOperacao(rs.getString(Tabelas.FILTRO_operacao).charAt(0));
            f.setValor(rs.getString(Tabelas.FILTRO_valor));
            lista.add(f);
        }
        return lista;
    } //buscar
}
